#include "road.h"

RoadNormal::RoadNormal(const double& r_width) {
    Rwidth = r_width;
    // SWIDTH表示窗口宽度
    left_boundary = SWIDTH / 2.0 - Rwidth;
    right_boundary = SWIDTH / 2.0 + Rwidth;
}

// 绘制道路
void RoadNormal::ShowRoad() {
    // 设置样条格式，宽度
    setlinestyle(PS_SOLID, 4);
    setlinecolor(BLACK);
    // 绘制两条左右道路边界线
    line(left_boundary, 0.0, left_boundary, SHEIGHT);
    line(right_boundary, 0.0, right_boundary, SHEIGHT);
}

RoadCrosswalk::RoadCrosswalk(const double& r_width) {
    // 车道宽度
    Rwidth = r_width;
    // 道路左边界
    left_boundary = SWIDTH / 2.0 - Rwidth;
    // 道路右边界
    right_boundary = SWIDTH / 2.0 + Rwidth;
    // 斑马线中心线
    mid_line = SHEIGHT / 2.0 - 200.0;
    // 斑马线上边界
    up_line = mid_line  - Rwidth / 2.0;
    // 斑马线下边界
    down_line = mid_line + Rwidth / 2.0;
}

void RoadCrosswalk::ShowRoad() {
    // 设置样条格式
    setlinestyle(PS_SOLID, 4);
    setlinecolor(BLACK);
    // 绘制左右道路边界
    line(left_boundary, 0.0, left_boundary, SHEIGHT);
    line(right_boundary, 0.0, right_boundary, SHEIGHT);
    // 绘制斑马线
    line(left_boundary, up_line, right_boundary, up_line);
    line(left_boundary, down_line, right_boundary, down_line);
    // 绘制斑马线里面的条纹
    // int i = 0;
    // while (true) {
    //     // 每个条纹上边界
    //     double up_bound = up_line - disRec;
    //     // 每个条纹下边界
    //     double down_bound = down_line + disRec;
    //     // 每个条纹左边界
    //     double left_bound = left_boundary + disRec * (1 + 2 * i);
    //     // 每个条纹右边界
    //     double right_bound = left_boundary + disRec * 2 * (i + 1);
    //     if (right_bound >= right_boundary) {
    //         break;
    //     }
    //     // 绘制矩形
    //     rectangle(left_bound, up_bound, right_bound, down_bound);
    //     i++;
    // }
    // int i = 0;
	// while (true)
	// {
	// 	double up_bound = up_line + disRec;
	// 	double down_bound = down_line - disRec;
	// 	double left_bound = left_boundary + disRec * (1 + 2 * i);
	// 	double right_bound = left_boundary + disRec * 2 * (i + 1);
	// 	if (right_bound >= right_boundary)
	// 	{
	// 		break;
	// 	}
	// 	rectangle(left_bound, up_bound, right_bound, down_bound);
	// 	i++;
	// }
}

// 双车道线道路
RoadDoubleLane::RoadDoubleLane(const double& r_width) {
    Rwidth = r_width;
    left_boundary = SWIDTH / 2.0 - Rwidth;
    right_boundary = SWIDTH / 2.0 + Rwidth;
}

void RoadDoubleLane::ShowRoad() {
    setfillstyle(PS_SOLID, 4);
    setfillcolor(BLACK);

    // 绘制两实线道路边界
    line(left_boundary, 0.0, left_boundary, SHEIGHT);
    line(right_boundary, 0.0, right_boundary, SHEIGHT);

    // 绘制中间虚线道路
    setfillstyle(PS_DASH, 4);
    line(SWIDTH / 2.0, 0.0, SWIDTH / 2.0, SHEIGHT);
}